package routines;

import java.util.Iterator;
import processors.CPU;
import datastructures.*;

public class Program {
	private MultiCollection routineNames;
	
	public Program() {
		routineNames = new MultiCollection();
	}
		
	/**
	 * adds a routinename to the program
	 */
	public void addRoutineName(String name){
		routineNames.insert(name);
	}

	/**
	 * returns 0, if no supported routine is found
	 * or the best runtime (> 0) for a given collection and cpu
	 * collection !=null
	 * cpu != null
	 */
	public int getBestRuntime(RoutineCollection collection, CPU cpu){
		
		int runtime = 0;
		Iterator<String> it = routineNames.getIterator();
		while(it.hasNext()) {
			Routine r = collection.getBestRoutine(it.next(), cpu);
			if (r == null)
				return 0;
			runtime += r.getRuntime();
		}
		
		return runtime;
	}
}
